﻿@using Fzrain.Core.Domain.Permission
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@Html.Partial("Components/Window")
<div  class="mainleft">
    @Html.Partial("Components/TreeView")
    @Html.Kendo().TreeView().Name("page-tree").DataSource(d => d.Read("GetDptTreeData", "Department")).DataTextField("Name").DataSpriteCssClassField("image"))
</div>
<div class="mainright">
    @(Html.Kendo().Grid<User>()
          .Name("grid").Excel(c => c.FileName("data"))
          .Columns(columns =>
          {
              columns.Bound(u => u.Id).Filterable(false)
                  .HeaderTemplate("<input type='checkbox' id='cbAll' >").HeaderHtmlAttributes(new { style = "text-align: center" })
                  .ClientTemplate("<input class='check_children'  type='checkbox' value='#=Id#'  />")

                  .Width(20);
              columns.Bound(u => u.Id).Width(20).Filterable(false);
              columns.Bound(u => u.UserName).Width(80);
              columns.Bound(u => u.Password).Width(80);
              columns.Bound(u => u.Birthday).Width(80).Format("{0:yyyy-MM-dd HH:mm:ss}");
              columns.Bound(u => u.Gender).Width(50).ClientTemplate("#=Gender=='0'?'男':'女'#");

              columns.Bound(u => u.Id).ClientTemplate("<i class='fa fa-cog' onclick=\"openWindowWithAjax(#=Id#,'User/Roles','设置角色')\"></i>").Width(24).Title("角色").Filterable(false);
              columns.Bound(u => u.Id).ClientTemplate("<i class='fa fa-search-plus' onclick=\"openWindowWithAjax(#=Id#,'User/Modules','设置权限')\"></i>").Width(24).Title("权限").Filterable(false);
              columns.Command(command =>
              {
                  command.Edit().CancelText("取消").UpdateText("保存"); command.Destroy();
              }).Width(80);
          })
          .ToolBar(toolbar =>
          {
              toolbar.Create().Text("新增");
              toolbar.Excel().Text("导出Excel");
              toolbar.Custom().Text("批量删除");
          })
          .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("../../User/UserEdit").Window(c => c.Title("用户信息").Scrollable(true).Name("editWindow")))
          .Pageable(c => c.PageSizes(true).Messages(m => m.ItemsPerPage("每页记录数")).Refresh(true))
          .Filterable()
          .Scrollable()
          .HtmlAttributes(new { style = "height:100%;" })
          .DataSource(dataSource => dataSource
              .Ajax()
              .PageSize(5)
              .Model(model =>
              {
                  model.Id(u => u.Id);
                  model.Field(u => u.Birthday).DefaultValue(DateTime.Now);
                
              })
              .Create(update => update.Action("Create", "User"))
              .Read(read => read.Action("Read", "User"))
              .Update(update => update.Action("Update", "User"))
              .Destroy(update => update.Action("Destroy", "User"))
          )
    )

</div>

<script type="text/javascript">
    $(function () {
        $("#cbAll").change(function () {
            $(".check_children").prop("checked", this.checked);
        });

    });
   
</script>

<style> 
    .k-edit-form-container {
        position: relative;
        width: 800px;
    } 
    td i:hover {
        color: #ff8300 ;
      
    }
</style>